package com.lagou.task1;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class Task1Driver {

    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        //本地调试输入
        args = new String[]{"D:\\cache\\hadoop\\data\\homeWork","D:\\cache\\hadoop\\data\\data\\out\\mr-homeWork"};

        //配置和job
        Configuration configuration = new Configuration();
        Job job = Job.getInstance(configuration);

        job.setJarByClass(Task1Driver.class);
        job.setMapperClass(Task1Mapper.class); //设置Map类
        job.setReducerClass(Task1Reducer.class); //设置Reducer类

        job.setMapOutputKeyClass(Task1BaseSort.class); //map输出key
        job.setMapOutputValueClass(NullWritable.class); //map输出value
        job.setOutputKeyClass(Text.class); //最终输出key
        job.setOutputValueClass(NullWritable.class); //最终输出value
        job.setNumReduceTasks(1); //设置reducer 1  U因为要全排序

        FileInputFormat.setInputPaths(job,new Path(args[0]));
        FileOutputFormat.setOutputPath(job,new Path(args[1]));

        boolean res = job.waitForCompletion(true);
        System.exit(res?0:1);
    }
}
